#ifndef NLISTWIDGET_H
#define NLISTWIDGET_H
#include <QtWidgets>
#include "tools/Gadget.h"


class P_LideleGate : public QStyledItemDelegate{

public:
    P_LideleGate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {excursion = 0;}

    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override {
        QRect draw_rect = painter->viewport();
        int text_start =  - excursion;
        QRect draw_nrect(text_start, draw_rect.y(), draw_rect.width(), draw_rect.height());
        painter->setViewport(draw_nrect);
        QStyledItemDelegate::paint(painter, option, index);
    }

    void setExcursion(int value)
    {
        excursion = value;
    }
private:
    int excursion;
};


class NListWidget : public QListWidget{

    Q_OBJECT

public:
    NListWidget(QWidget *parent = nullptr, bool autoExit=false);

    ~NListWidget(){
        delete delegate;
    }

    void del(int row);

    void unselected();

    void put(int &give);

    void desc();

    void clear();

    void sclear();

    int minor();

    std::pair<int, int> getMaxlenght();

    QList<QListWidgetItem *> all();

    P_LideleGate* itemDelegate(){
        return delegate;
    }

private:
    bool winflag;
    Extend definfc;
    QTimer delayHideTimer;
    QWidget *unvoidw = new QWidget(this);
    P_LideleGate *delegate = new P_LideleGate(this);

    void enterEvent(QEnterEvent *event);

    void leaveEvent(QEvent *event);

    void changeEvent(QEvent *event);

signals:
    void msev_drop(std::pair<bool, QStringList>);
    void msev_rls(bool);
    void msev_wheel(int);
    void msev_invisible();
};
#endif
